// import vue from 'vue'
// import Vuex from 'vuex'
// vue.use(Vuex)
// import persistedState from 'vuex-persistedstate'
// import index from '../shitu/index'
// export default new Vuex.Store({
//     //储存数据， 相当于data
//     state: {
//         num: 1,
//         str: '我是vuex',
//         bool: true,
//         obj: { name: '张三' },
//         arr: [1, 2, 3],
//         sum: 0

//     },
//     //计算属性， 相当于computed
//     getters: {
//         comName(state) {
//             return state.num
//         }
//     },
//     // 直接修改state里面的数据源
//     mutations: {
//         // 第一个参数位是数据源，第二个参数是所传的值
//         changeSum(state, val) {
//             state.num += val
//         },
//         changenum(state, val) {
//             state.num -= val
//             console.log(val);
//         },
//         changeSumto(state, val) {
//             state.num += val
//         },
//         deadd(state, val) {
//             state.num += val
//         }
//     },
//     // 异步修改数据state里面的数据源
//     actions: {
//         actnum(state, val) {

//         }
//     },
//     // 模块化vuex,相当于仓库
//     modules: {
//         index
//     },
//     // 数据持久化
//     plugins: [persistedState()]
// })

import Vue from "vue"
import Vuex from "vuex"
Vue.use(Vuex)
import persistedState from 'vuex-persistedstate'
const stroe = new Vuex.Store({
    //数据源 相当于data
    state: {
        new: [],
        // 商品数据管理
        shopData: [{
            id: '12987122',
            name: '好滋好味鸡蛋仔',
            category: '江浙小吃、小吃零食',
            desc: '荷兰优质淡奶，奶香浓而不腻',
            address: '上海市普陀区真北路',
            shop: '王小虎夫妻店',
            shopId: '10333'
        }, {
            id: '12987123',
            name: '好滋好味鸡蛋仔',
            category: '江浙小吃、小吃零食',
            desc: '荷兰优质淡奶，奶香浓而不腻',
            address: '上海市普陀区真北路',
            shop: '王小虎夫妻店',
            shopId: '10333'
        }, {
            id: '12987125',
            name: '好滋好味鸡蛋仔',
            category: '江浙小吃、小吃零食',
            desc: '荷兰优质淡奶，奶香浓而不腻',
            address: '上海市普陀区真北路',
            shop: '王小虎夫妻店',
            shopId: '10333'
        }, {
            id: '12987126',
            name: '好滋好味鸡蛋仔',
            category: '江浙小吃、小吃零食',
            desc: '荷兰优质淡奶，奶香浓而不腻',
            address: '上海市普陀区真北路',
            shop: '王小虎夫妻店',
            shopId: '10333'
        }, {
            id: '12987125',
            name: '好滋好味鸡蛋仔',
            category: '江浙小吃、小吃零食',
            desc: '荷兰优质淡奶，奶香浓而不腻',
            address: '上海市普陀区真北路',
            shop: '王小虎夫妻店',
            shopId: '10333'
        }, , {
            id: '12987125',
            name: '好滋好味鸡蛋仔',
            category: '江浙小吃、小吃零食',
            desc: '荷兰优质淡奶，奶香浓而不腻',
            address: '上海市普陀区真北路',
            shop: '王小虎夫妻店',
            shopId: '10333'
        }, , {
            id: '12987125',
            name: '好滋好味鸡蛋仔',
            category: '江浙小吃、小吃零食',
            desc: '荷兰优质淡奶，奶香浓而不腻',
            address: '上海市普陀区真北路',
            shop: '王小虎夫妻店',
            shopId: '10333'
        }, , {
            id: '12987125',
            name: '好滋好味鸡蛋仔',
            category: '江浙小吃、小吃零食',
            desc: '荷兰优质淡奶，奶香浓而不腻',
            address: '上海市普陀区真北路',
            shop: '王小虎夫妻店',
            shopId: '10333'
        }, , {
            id: '12987125',
            name: '好滋好味鸡蛋仔',
            category: '江浙小吃、小吃零食',
            desc: '荷兰优质淡奶，奶香浓而不腻',
            address: '上海市普陀区真北路',
            shop: '王小虎夫妻店',
            shopId: '10333'
        },],
        // 用户数据管理
        tableData: [{
            date: '2016-05-03',
            name: '王小虎',
            province: '上海',
            city: '普陀区',
            address: '上海市普陀区金沙江路 1518 弄',
            zip: 200333
        }, {
            date: '2016-05-02',
            name: '王小虎',
            province: '上海',
            city: '普陀区',
            address: '上海市普陀区金沙江路 1518 弄',
            zip: 200333
        }, {
            date: '2016-05-04',
            name: '王小虎',
            province: '上海',
            city: '普陀区',
            address: '上海市普陀区金沙江路 1518 弄',
            zip: 200333
        }, {
            date: '2016-05-01',
            name: '王小虎',
            province: '上海',
            city: '普陀区',
            address: '上海市普陀区金沙江路 1518 弄',
            zip: 200333
        }, {
            date: '2016-05-08',
            name: '王小虎',
            province: '上海',
            city: '普陀区',
            address: '上海市普陀区金沙江路 1518 弄',
            zip: 200333
        }, {
            date: '2016-05-06',
            name: '王小虎',
            province: '上海',
            city: '普陀区',
            address: '上海市普陀区金沙江路 1518 弄',
            zip: 200333
        }, {
            date: '2016-05-07',
            name: '王小虎',
            province: '上海',
            city: '普陀区',
            address: '上海市普陀区金沙江路 1518 弄',
            zip: 200333
        }, {
            date: '2016-05-02',
            name: '王小虎',
            province: '上海',
            city: '普陀区',
            address: '上海市普陀区金沙江路 1518 弄',
            zip: 200333
        }, {
            date: '2016-05-02',
            name: '王小虎',
            province: '上海',
            city: '普陀区',
            address: '上海市普陀区金沙江路 1518 弄',
            zip: 200333
        }, {
            date: '2016-05-02',
            name: '王小虎',
            province: '上海',
            city: '普陀区',
            address: '上海市普陀区金沙江路 1518 弄',
            zip: 200333
        }, {
            date: '2016-05-02',
            name: '王小虎',
            province: '上海',
            city: '普陀区',
            address: '上海市普陀区金沙江路 1518 弄',
            zip: 200333
        }, {
            date: '2016-05-02',
            name: '王小虎',
            province: '上海',
            city: '普陀区',
            address: '上海市普陀区金沙江路 1518 弄',
            zip: 200333
        }, {
            date: '2016-05-02',
            name: '王小虎',
            province: '上海',
            city: '普陀区',
            address: '上海市普陀区金沙江路 1518 弄',
            zip: 200333
        }, {
            date: '2016-05-02',
            name: '王小虎',
            province: '上海',
            city: '普陀区',
            address: '上海市普陀区金沙江路 1518 弄',
            zip: 200333
        }, {
            date: '2016-05-02',
            name: '王小虎',
            province: '上海',
            city: '普陀区',
            address: '上海市普陀区金沙江路 1518 弄',
            zip: 200333
        }],
        //手机出货量,当日,当月 总计
        mobilePhoneShipmentVolume: [{
            name: 'oppo',
            day: 121,
            month: 1536,
            total: 3534
        }, {
            name: 'vivo',
            day: 131,
            month: 4352,
            total: 3453
        }, {
            name: '小米',
            day: 143,
            month: 4303,
            total: 6856
        }, {
            name: '华为',
            day: 123,
            month: 2324,
            total: 3867
        }, {
            name: 'iphone',
            day: 112,
            month: 2334,
            total: 4653
        }, {
            name: '三星',
            day: 123,
            month: 2312,
            total: 3214
        },],
        //手机厂商
        mobilePhoneManufacturer: ['小米', 'oppo', '华为', 'vivo', 'iphone', '三星'],
        //折线图数据
        mylineChart_data: {
            mi: [723, 236, 234, 634, 652, 567, 745],
            huawei: [322, 323, 522, 432, 562, 532, 132],
            vivo: [523, 345, 123, 421, 233, 112, 345],
            oppo: [231, 344, 512, 321, 123, 432, 99],
            iphone: [156, 321, 356, 324, 633, 421, 955],
            sansong: [123, 200, 57, 99, 109, 100, 76]
        },
        //最近七天
        lastSevenDays: ['3-1', '3-2', '3-3', '3-4', '3-5', '3-6', '3-7'],
        //饼图数据
        salesProportionInThePastMonth: [
            { value: 335, name: '小米' },
            { value: 310, name: 'oppo' },
            { value: 234, name: '华为' },
            { value: 135, name: 'vivo' },
            { value: 548, name: 'iphone' },
            { value: 158, name: '三星' },
        ]
    },
    //相当于计算属性computed
    getters: {},
    //直接修改state里面的数据源
    mutations: {
        delet(state, val) {
            state.tableData.splice(val, 1)
        },
        push_userdata(state, val) {
            Vue.set(state, 'userdata', val)
        },
        push_userdata_singe(state, val) {
            Vue.set(state.userdata, state.userdata.length, val)
        },
        delete_user(state, val) {
            for (let i = 0; i < state.userdata.length; i++) {
                if (state.userdata[i].id == val) {
                    state.userdata.splice(i, 1)
                }
            }
        },
        edit_user(state, val) {
            for (let i = 0; i < state.userdata.length; i++) {
                if (state.userdata[i].id == val.id) {
                    Vue.set(state.userdata, i, val)
                }
            }
        },
        change_lastLoginTime(state, val) {
            Vue.set(state.administrators, 'lastLoginTime', val)
        },
        Adduser(state, val) {
            state.tableData.unshift(val)
            state.new.push(val)
        }
    },
    //一般用于异步修改数据 (axios,定时器，延时器，事件)
    actions: {
        actions_push_userdata_singe(content, val) {
            content.commit('push_userdata_singe', val)
        },
        actions_delete_user(content, val) {
            content.commit('delete_user', val)
        },
        actions_edit_user(content, val) {
            content.commit('edit_user', val)
        }
    },
    //模块化vuex
    modules: {
        // shopinfo
    },
    plugins: [persistedState()]
})
export default stroe